import {_decorator, Component} from 'cc';
import {Constant} from "../../config/Constant";
import {logUtil} from "../util/logUtil";

const {ccclass} = _decorator;
export class coinProperty {
    //金币数量
    amount: number =1;
    //金币掉落时间
    dropTime: number =0;
    //金币持续时间
    liftTime: number =Constant.GAME_SET.CoinliftTime;
    //是否可拾取
    isCollectible: boolean =false;
    //金币位置
    position: number | null;
}

@ccclass('CoinManager')
export class CoinManager extends Component {
    //金币属性
    coinProperty: coinProperty = new coinProperty();

    //日志控制器
    log = logUtil.instance
    logLevel = "CoinManager"

    fire() {
        this.coinProperty.dropTime = 0;
    }

    update(deltaTime: number) {
        this.coinProperty.dropTime += deltaTime;
        //定时销毁
        if (this.coinProperty.dropTime >= this.coinProperty.liftTime) {
            this.log.log("fight", `自动拾取1`)
            //onCoinCollect;onKilled
            this.node.emit(Constant.EVENT_NAME.onCoinCollect, this.node);
        }
    }
}
